package com.tulele.vtool.utils;

import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
import com.tulele.vtool.model.UserInfo;
import com.tulele.vtool.model.combinedEntity.CustomerMarqueeInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.joda.time.DateTime;
import org.terracotta.offheapstore.HashingMap;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
public class ToolUtil {

    /**
     * 推送文本处理(IOS)
     * @param msg 推送文本内容
     * @return 处理后的
     * @throws Exception
     */
    public static String handleMsgmenuidByIOS(String msg) throws Exception {
        msg = msg.replace("msgmenuid=+++","msgmenuid= ");
        return msg;
    }

    /**
     * MD5方法
     * @param text 明文
     * @return 密文
     * @throws Exception
     */
    public static String md5Encode(String text) throws Exception {
        //加密后的字符串
        String encodeStr= DigestUtils.md5Hex(text + SysConstant.MD5_KEY);
        log.info("[encodeStr] = " + encodeStr);
        return encodeStr;
    }

    /**
     * MD5验证方法
     * @param text 明文
     * @param md5 密文
     * @return true/false
     * @throws Exception
     */
    public static boolean verify(String text, String md5) throws Exception {
        //根据传入的密钥进行验证
        String md5Text = md5Encode(text);
        if(md5Text.equalsIgnoreCase(md5))
        {
            log.info("verify succ");
            return true;
        }

        return false;
    }

    /**
     * 生成md5
     *
     * @param message
     * @return
     */
    public static String getMD5(String message) {
        String md5str = "";
        try {
            // 1 创建一个提供信息摘要算法的对象，初始化为md5算法对象
            MessageDigest md = MessageDigest.getInstance("MD5");

            // 2 将消息变成byte数组
            byte[] input = message.getBytes();

            // 3 计算后获得字节数组,这就是那128位了
            byte[] buff = md.digest(input);

            // 4 把数组每一字节（一个字节占八位）换成16进制连成md5字符串
            md5str = bytesToHex(buff);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return md5str.toLowerCase();
    }

    /**
     * 二进制转十六进制
     *
     * @param bytes
     * @return
     */
    public static String bytesToHex(byte[] bytes) {
        StringBuffer md5str = new StringBuffer();
        // 把数组每一字节换成16进制连成md5字符串
        int digital;
        for (int i = 0; i < bytes.length; i++) {
            digital = bytes[i];

            if (digital < 0) {
                digital += 256;
            }
            if (digital < 16) {
                md5str.append("0");
            }
            md5str.append(Integer.toHexString(digital));
        }
        return md5str.toString().toUpperCase();
    }

    /**
     * 随机指定范围内N个不重复的数
     * 在初始化的无重复待选数组中随机产生一个数放入结果中，
     * 将待选数组被随机到的数，用待选数组(len-1)下标对应的数替换
     * 然后从len-2里随机产生下一个随机数，如此类推
     * @param max  指定范围最大值
     * @param min  指定范围最小值
     * @param n  随机数个数
     * @return int[] 随机数结果集
     */
    public static int[] randomArray(int min,int max,int n){
        int len = max-min+1;

        if(max < min || n > len){
            return null;
        }

        //初始化给定范围的待选数组
        int[] source = new int[len];
        for (int i = min; i < min+len; i++){
            source[i-min] = i;
        }

        int[] result = new int[n];
        Random rd = new Random();
        int index = 0;
        for (int i = 0; i < result.length; i++) {
            //待选数组0到(len-2)随机一个下标
            index = Math.abs(rd.nextInt() % len--);
            //将随机到的数放入结果集
            result[i] = source[index];
            //将待选数组中被随机到的数，用待选数组(len-1)下标对应的数替换
            source[index] = source[len];
        }
        return result;
    }

    /**
     * 随机指定范围内的不重复的数
     * 在初始化的无重复待选数组中随机产生一个数放入结果中，
     * 将待选数组被随机到的数，用待选数组(len-1)下标对应的数替换
     * 然后从len-2里随机产生下一个随机数，如此类推
     * @param max  指定范围最大值
     * @param min  指定范围最小值
     */
    public static int randomNum(int min,int max) {

        Random random = new Random();

        int s = random.nextInt(max)%(max-min+1) + min;

        return s;
    }

    /**
     * 获取字符串化浏览次数
     * @param browseCount
     * @return
     */
    public static String getMicroVideoBrowseCount(int browseCount) {

        if (browseCount < 0) {

            return String.format("%d", 0);

        } else if (browseCount < 10000) {

            return String.format("%d", browseCount);

        } else {

            return String.format("%.1fw", browseCount / 10000.0f);

        }

    }

    /**
     * 计算给定时间与当前的时间差 单位：秒
     * @param date
     * @return
     */
    public static long secondDiff(Date date) {
        Instant specialDateInstant = date.toInstant();

        ZoneId zone = ZoneId.systemDefault();
        LocalDateTime specialDateTime = LocalDateTime.ofInstant(specialDateInstant, zone);
        System.out.println(specialDateTime);
        LocalDateTime now = LocalDateTime.now();

        return ChronoUnit.SECONDS.between(specialDateTime, now);

    }

    /**
     * 通过身份证号码获取出生日期、性别、年龄
     * @param certificateNo
     * @return 返回的出生日期格式：1990-01-01   性别格式：F-女，M-男
     */
    public static Map<String, String> getBirAgeSex(String certificateNo) {
        String birthday = "";
        String age = "";
        String sexCode = "";

        int year = Calendar.getInstance().get(Calendar.YEAR);
        char[] number = certificateNo.toCharArray();
        boolean flag = true;
        if (number.length == 15) {
            for (int x = 0; x < number.length; x++) {
                if (!flag) return new HashMap<String, String>();
                flag = Character.isDigit(number[x]);
            }
        } else if (number.length == 18) {
            for (int x = 0; x < number.length - 1; x++) {
                if (!flag) return new HashMap<String, String>();
                flag = Character.isDigit(number[x]);
            }
        }
        if (flag && certificateNo.length() == 15) {
            birthday = "19" + certificateNo.substring(6, 8) + "-"
                    + certificateNo.substring(8, 10) + "-"
                    + certificateNo.substring(10, 12);
            sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 3, certificateNo.length())) % 2 == 0 ? "F" : "M";
            age = (year - Integer.parseInt("19" + certificateNo.substring(6, 8))) + "";
        } else if (flag && certificateNo.length() == 18) {
            birthday = certificateNo.substring(6, 10) + "-"
                    + certificateNo.substring(10, 12) + "-"
                    + certificateNo.substring(12, 14);
            sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 4, certificateNo.length() - 1)) % 2 == 0 ? "F" : "M";
            age = (year - Integer.parseInt(certificateNo.substring(6, 10))) + "";
        }
        Map<String, String> map = new HashMap<String, String>();
        map.put("birthday", birthday);
        map.put("age", age);
        map.put("sexCode", sexCode);
        return map;
    }

    /**
     * 通过身份证号码获取出生日期
     * @param certificateNo
     * @return 返回的出生日期格式：1990-01-01
     */
    public static String getBirthdayByIdCard(String certificateNo) {
        String birthday = "";

        char[] number = certificateNo.toCharArray();
        boolean flag = true;
        if (number.length == 15) {
            for (int x = 0; x < number.length; x++) {
                if (!flag) {
                    return "";
                }
                flag = Character.isDigit(number[x]);
            }
        } else if (number.length == 18) {
            for (int x = 0; x < number.length - 1; x++) {
                if (!flag) {
                    return "";
                }
                flag = Character.isDigit(number[x]);
            }
        }
        if (flag && certificateNo.length() == 15) {
            birthday = "19" + certificateNo.substring(6, 8) + "-"
                    + certificateNo.substring(8, 10) + "-"
                    + certificateNo.substring(10, 12);
        } else if (flag && certificateNo.length() == 18) {
            birthday = certificateNo.substring(6, 10) + "-"
                    + certificateNo.substring(10, 12) + "-"
                    + certificateNo.substring(12, 14);
        }

        return birthday;
    }

    /**
     * 根据用户生日计算年龄
     */
    public static int getAgeByBirthday(String bir) {

        if(org.apache.commons.lang3.StringUtils.isBlank(bir)){
            return 0;
        }

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate birthDate = LocalDate.parse(bir, formatter);

        LocalDate nowDate = LocalDate.now();
        Period period = Period.between(birthDate, nowDate);

        return period.getYears();
    }

    /**
     * 根据身份证号码计算年龄
     */
    public static int getAgeByIdCard(String certificateNo) {

        String bir = getBirthdayByIdCard(certificateNo);

        if(org.apache.commons.lang3.StringUtils.isBlank(bir)){
            return 0;
        }

        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        LocalDate birthDate = LocalDate.parse(bir, formatter);

        LocalDate nowDate = LocalDate.now();
        Period period = Period.between(birthDate, nowDate);

        return period.getYears();
    }

    /**
     * 获取客户端IP地址
     * @param request
     * @return
     */
    public static String getIpAddress(HttpServletRequest request) {

        String ipAddress = request.getHeader("x-forwarded-for");

        if(ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
            ipAddress = request.getHeader("Proxy-Client-IP");
        }
        if (ipAddress == null || ipAddress.length() == 0 || "unknow".equalsIgnoreCase(ipAddress)) {
            ipAddress = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
            ipAddress = request.getRemoteAddr();

            if(ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")){
                //根据网卡获取本机配置的IP地址
                InetAddress inetAddress = null;
                try {
                    inetAddress = InetAddress.getLocalHost();
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                }
                ipAddress = inetAddress.getHostAddress();
            }
        }

        //对于通过多个代理的情况，第一个IP为客户端真实的IP地址，多个IP按照','分割
        if(null != ipAddress && ipAddress.length() > 15){
            //"***.***.***.***".length() = 15
            if(ipAddress.indexOf(",") > 0){
                ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
            }
        }

        return ipAddress;
    }

    /**
     * 视频内容检查生效状态
     * @return
     */
    public static boolean getVideoContentCheckEffectStatus(){

        LocalDateTime localDateTime = LocalDateTime.now();

        int hour = localDateTime.getHour();

        if (hour >= 19 && hour <=22) {
            return true;
        }

        return false;
    }

    /**
     * 产生用户唯一标识
     * @return
     */
    public static String generateUserUniqueId() {

        long second = LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8"));

        String secondStr = String.valueOf(second);

        int randonNum = randomNum(10000000, 99999999);

        String tempSecondStr = secondStr.substring(1);

        long finalUniqueId = Long.parseLong(tempSecondStr) + randonNum;

        return String.valueOf(finalUniqueId);
    }

    /**
     * 产生订单ID
     * @return
     */
    public static String generateOrderId() {

        String dateString = DateUtil.getFormatDate("yyyyMMddHHmmssSSS", DateTime.now());

        int randonNum = randomNum(1000000, 9999999);

        return dateString + randonNum;

    }

    /**
     * 获取是否是夜间状态 true-是夜间时段 false-不是夜间时段
     * @return
     */
    public static boolean getNightTimePeriodStatus(){

        LocalDateTime localDateTime = LocalDateTime.now();

        int hour = localDateTime.getHour();

        if (hour == 23 || (hour <= 6 && hour >= 0)) {
            return true;
        }

        return false;
    }

    /**
     * 获取是否是上午状态 true-是上午时段 false-下午时段
     * @return
     */
    public static boolean getAmPmTimePeriodStatus(){

        LocalDateTime localDateTime = LocalDateTime.now();

        int hour = localDateTime.getHour();

        if (hour >= 0 && hour <= 14) {
            return true;
        }

        return false;
    }

    /**
     * 下载头像
     * @param imgUrl
     * @param userId
     * @param newImgName
     * @throws Exception
     */
    public static File downloadAvatarPic(String imgUrl, Integer userId, String newImgName) throws Exception {
        CloseableHttpClient closeableHttpClient = HttpClients.createDefault(); //1、创建实例
        HttpGet httpGet = new HttpGet(imgUrl); //2、创建请求

        CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpGet); //3、执行
        HttpEntity httpEntity = closeableHttpResponse.getEntity(); //4、获取实体

        File destFile = new File(SysConstant.WX_AVATAR_DOWNLOAD_PATH + userId + "/" + newImgName);

        if(httpEntity!=null) {

            InputStream inputStream = httpEntity.getContent();
            FileUtils.copyToFile(inputStream, destFile); //将图片保存在本次磁盘D盘，命名为xxx.png

            inputStream.close();
        }

        closeableHttpResponse.close();
        closeableHttpClient.close();

        return destFile;
    }

    /**
     * 下载头像
     * @param imgUrl
     * @param userId
     * @param newImgName
     * @throws Exception
     */
    public static File downloadAvatarPic(String imgUrl, Integer userId, String newImgName,String avatarPath) throws Exception {
        CloseableHttpClient closeableHttpClient = HttpClients.createDefault(); //1、创建实例
        HttpGet httpGet = new HttpGet(imgUrl); //2、创建请求

        CloseableHttpResponse closeableHttpResponse = closeableHttpClient.execute(httpGet); //3、执行
        HttpEntity httpEntity = closeableHttpResponse.getEntity(); //4、获取实体

        File destFile = new File(avatarPath + userId + "/" + newImgName);

        if(httpEntity!=null) {

            InputStream inputStream = httpEntity.getContent();
            FileUtils.copyToFile(inputStream, destFile); //将图片保存在本次磁盘D盘，命名为xxx.png

            inputStream.close();
        }

        closeableHttpResponse.close();
        closeableHttpClient.close();

        return destFile;
    }

    /**
     * 从list中随机抽取元素
     * @param list
     * @param n
     * @return
     */
    private static List createRandomList(List list, int n) {
        Map map = new HashMap();
        List listNew = new ArrayList();
        if (list.size() <= n) {
            return list;
        } else {
            while (map.size() < n) {
                int random = (int) (Math.random() * list.size());
                if (!map.containsKey(random)) {
                    map.put(random, "");
                    listNew.add(list.get(random));
                }
            }
            return listNew;
        }
    }

    public static List<CustomerMarqueeInfo> getCustomerMarqueeInfoBySpecialSize(int recordSize) {

        CustomerMarqueeInfo customerMarqueeOne = new CustomerMarqueeInfo();
        customerMarqueeOne.setAvatarUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/jiaopeiheads/1.jpg");
//        customerMarqueeOne.setCustomerInfo("陈婷婷 刚刚在人脉广场加了2个客户");
        customerMarqueeOne.setCustomerInfo("陈婷婷 刚刚添加了2个客户");

        CustomerMarqueeInfo customerMarqueeTwo = new CustomerMarqueeInfo();
        customerMarqueeTwo.setAvatarUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/jiaopeiheads/2.jpg");
        customerMarqueeTwo.setCustomerInfo("孟春然 上周添加了16个客户");

        CustomerMarqueeInfo customerMarqueeThree = new CustomerMarqueeInfo();
        customerMarqueeThree.setAvatarUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/jiaopeiheads/3.jpg");
        customerMarqueeThree.setCustomerInfo("高进锋 3分钟前添加了一个客户");

        CustomerMarqueeInfo customerMarqueeFour = new CustomerMarqueeInfo();
        customerMarqueeFour.setAvatarUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/jiaopeiheads/4.jpg");
        customerMarqueeFour.setCustomerInfo("李海芳 正在追踪客户中......");

        CustomerMarqueeInfo customerMarqueeFive = new CustomerMarqueeInfo();
        customerMarqueeFive.setAvatarUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/wxTouXiang/jiaopeiheads/5.jpg");
        customerMarqueeFive.setCustomerInfo("梁嘉 上周锁定9个意向客户");

        List<CustomerMarqueeInfo> marqueeInfo = Lists.newArrayList();

        if (recordSize == 1) {

            marqueeInfo = Arrays.asList(customerMarqueeOne);

        } else if (recordSize == 2) {

            marqueeInfo = Arrays.asList(customerMarqueeOne, customerMarqueeTwo);

        } else if (recordSize == 3) {

            marqueeInfo = Arrays.asList(customerMarqueeOne, customerMarqueeTwo, customerMarqueeThree);

        } else if (recordSize == 4) {

            marqueeInfo = Arrays.asList(customerMarqueeOne, customerMarqueeTwo, customerMarqueeThree, customerMarqueeFour);

        } else if (recordSize == 5) {

            marqueeInfo = Arrays.asList(customerMarqueeOne, customerMarqueeTwo, customerMarqueeThree, customerMarqueeFour, customerMarqueeFive);

        }


        return marqueeInfo;
    }

    /**
     * 获取字符串化浏览次数
     * @param vipLev
     * @return
     */
    public static int getVipBonus(int vipLev) {

        int vipBonus = 149;

        if (vipLev == 1) {
            vipBonus = 149;
        } else if (vipLev == 2) {
            vipBonus = 199;
        } else if (vipLev == 3) {
            vipBonus = 299;
        }

        return vipBonus;
    }

    public static void main(String[] args) throws Exception {
        //System.out.println(randomNum(80, 90));
        //System.out.println(getMicroVideoBrowseCount(556686));

        //System.out.println(idCardVerify("410725198809062838", "别赛男"));

        //Date date = new Date(2018, 3, 10, 16, 10, 10);
        //System.out.println(date);

        //System.out.println(secondDiff(date));
//        System.out.println(getBirAgeSex("410725198909062838"));
//        System.out.println(getAgeByBirthday("2000-04-21"));
//        System.out.println(getBirthdayByIdCard("41072519890906283x"));
//        System.out.println(getAgeByIdCard("41072520000421283x"));

//        System.out.println(LocalDateTime.now());
//        //System.out.println(LocalDateTime.now() + " " + checkIpAddrCnSource("195.16.187.50"));
//        System.out.println(LocalDateTime.now());
//
//        System.out.println(randomNum(100000000, 999999999));
//        System.out.println(generateUserUniqueId());
//
//        System.out.println(generateOrderId());

        //System.out.println(md5Encode(1000005 + "oQdug0Sbss2o6K9Ckfgl7Vki1oF8"));

        //System.out.println(md5Encode("1000005oQdug0Sbss2o6K9Ckfgl7Vki1oF8"));

        //downloadAvatarPic("http://thirdwx.qlogo.cn/mmopen/fFgUJknhibCwWFr6ibmJR4ibo1vMS1V7QyZRBy3nug8lib5bV1C5WhvWPhDJojn3R6KLdNWW0eq0wkOeTkAZZVC9tA/132", "1000006_avatar.png");

//        List<String> a = Arrays.asList("10000013,10000015,10000047,10000062,10000076,10000240".split(","));
//        a.forEach(info -> System.out.println(info));

        //路径   这里写一个路径进去
        //String path="D:\\变声器\\语音包2.0资源(1)\\语音包2.0资源";
        //调用方法
        //getFiles(path);

//        String str="我们都爱中国";//定义的字符串
//
//        int len = str.length();
//        String[] strAry = new String[len];
//        for(int i=0;i<str.length();i++){//通过length方法获取字符串长度
//            strAry[i] = String.valueOf(str.charAt(i));//charAt是取字符串第i个字符
//
//        }
//
//        String a = String.join("|",Arrays.asList(strAry));
//        System.out.println(a);
//
        //md5Encode("10000232olw0Q1P9l6Vo4TJntRVtf3YysSCk");

        String path="D:\\变声器\\趣味视频";
//        getFiles(path);

//        Integer i0 = new Integer(300);
//        Integer i1 = new Integer(300);
//        int i2 = 300;
//        System.out.println(i0 == i1);
//        System.out.println(i0.equals(i1));
//        System.out.println(i0 == i2);

        //System.out.println(md5Encode(10237136 + "odYNF0cKjBInV8hKsIfW8WBiiqVs"));

        int vipSerivceBonus = Double.valueOf(198 / 2).intValue();
        System.out.println(vipSerivceBonus);
        System.out.println(99 + 0d);
    }

    public static void getFiles(String path) {

        String urlPrefix = "https://magic-voicetrans.oss-cn-shenzhen.aliyuncs.com/platformMediaSource";

        File file = new File(path);
        // 如果这个路径是文件夹
        if (file.isDirectory()) {
            // 获取路径下的所有文件
            File[] files = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                // 如果还是文件夹 递归获取里面的文件 文件夹
                if (files[i].isDirectory()) {
                    //System.out.println("目录：" + files[i].getPath());
                    getFiles(files[i].getPath());
                } else {
                    //System.out.println("文件1：" + files[i].getPath());

                    String filePath = files[i].getPath();

                    String url = filePath.substring(filePath.indexOf("D:\\变声器\\趣味视频") + 11);

                    String url2 = url.replace("\\", "/");

                    String finalUrl = urlPrefix + url2;

                    System.out.println(finalUrl);
                }

            }
        } else {
            System.out.println("文件2：" + file.getPath());
        }
    }

    public static List<UserInfo> getMineTwoAndTwo() {
        Map<String, String> NeedListOne =new HashMap<>();
        NeedListOne.put("identityName","articleTypeIds: [\"1\", \"2\", \"3\", \"4\", \"5\", \"115224\", \"115225\", \"115226\", \"115227\", \"115228\", \"115218\", \"115219\"]");
        NeedListOne.put("needName","找项目 找代理 找下级 赚钱 副业");

        UserInfo UserInfoOne = new UserInfo();
        UserInfoOne.setAvatarUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/headImgs/20210909/fd133dac-8f56-4004-9bd1-0a4b6f592aeb.jpg");
        UserInfoOne.setBrandNames("淘特");
        UserInfoOne.setNeedList(NeedListOne);
        UserInfoOne.setNickName("纯免费--福利官:若薇");
        UserInfoOne.setRegion("北京");
        UserInfoOne.setTelNum("13*******11");
        UserInfoOne.setUserId(6604494);
        UserInfoOne.setVipStatus(1);

        Map<String, String> NeedListTwo =new HashMap<>();
        NeedListTwo.put("identityName","个体户 代理商");
        NeedListTwo.put("needName","找项目 找代理 找下级 赚钱 副业");

        UserInfo UserInfoTwo = new UserInfo();
        UserInfoTwo.setAvatarUrl("http://thirdwx.qlogo.cn/mmopen/Gnt1UCQBIGsHJsHRIlFV6xfzhdTOKhjBNjDsoYQFV2rUmKib56Sofkn3RWYvHfbdUYk6RFLIPQgfXibBfR7yH3Wrs5D3HiaiajCo/132");
        UserInfoTwo.setBrandNames("销售技巧,黄帝内经,全民健康,销售心态,艾家羊奶");
        UserInfoTwo.setNeedList(NeedListTwo);
        UserInfoTwo.setNickName("鹏飞&-已购双封");
        UserInfoTwo.setRegion("广东,中山");
        UserInfoTwo.setTelNum("18*******32");
        UserInfoTwo.setUserId(2308581);
        UserInfoTwo.setVipStatus(1);

        List<UserInfo> ddd = Arrays.asList(UserInfoOne,UserInfoTwo);

        return ddd;
    }

    public static UserInfo OneCoster() {
        Map<String, String> NeedListOne =new HashMap<>();
        NeedListOne.put("identityName","个体户 代理商");
        NeedListOne.put("needName","找项目 找代理 找下级 赚钱 副业");

        UserInfo UserInfoOne = new UserInfo();
        UserInfoOne.setAvatarUrl("https://zktuistatic.oss-cn-shenzhen.aliyuncs.com/headImgs/20210909/fd133dac-8f56-4004-9bd1-0a4b6f592aeb.jpg");
        UserInfoOne.setBrandNames("淘特");
        UserInfoOne.setNeedList(NeedListOne);
        UserInfoOne.setNickName("纯免费--福利官:若薇");
        UserInfoOne.setRegion("北京");
        UserInfoOne.setTelNum("13*******11");
        UserInfoOne.setUserId(6604494);
        UserInfoOne.setVipStatus(1);

        return UserInfoOne;
    }

    public static UserInfo TwoCoster() {
        Map<String, String> NeedListTwo =new HashMap<>();
        NeedListTwo.put("identityName","个体户 代理商");
        NeedListTwo.put("needName","找项目 找代理 找下级 赚钱 副业");

        UserInfo UserInfoTwo = new UserInfo();
        UserInfoTwo.setAvatarUrl("http://thirdwx.qlogo.cn/mmopen/Gnt1UCQBIGsHJsHRIlFV6xfzhdTOKhjBNjDsoYQFV2rUmKib56Sofkn3RWYvHfbdUYk6RFLIPQgfXibBfR7yH3Wrs5D3HiaiajCo/132");
        UserInfoTwo.setBrandNames("销售技巧,黄帝内经,全民健康,销售心态,艾家羊奶");
        UserInfoTwo.setNeedList(NeedListTwo);
        UserInfoTwo.setNickName("鹏飞&-已购双封");
        UserInfoTwo.setRegion("广东,中山");
        UserInfoTwo.setTelNum("18*******32");
        UserInfoTwo.setUserId(2308581);
        UserInfoTwo.setVipStatus(1);

        return UserInfoTwo;
    }

    /**
     * 判断文件大小
     * // 上传文件格式
     * MultipartFile multipartFile = null;
     * // 文件不大于100M
     * FileUtil.checkFileSize( multipartFile.getSize(),100,"M");
     *
     * // 上传文件格式
     * File file = null;
     * // 文件不大于100M
     * FileUtil.checkFileSize( file.length(),100,"M")
     *
     * @param len
     *            文件长度
     * @param size
     *            限制大小
     * @param unit
     *            限制单位（B,K,M,G）
     * @return
     */
    public static boolean checkFileSize(Long len, int size, String unit) {
//        long len = file.length();
        double fileSize = 0;
        if ("B".equals(unit.toUpperCase())) {
            fileSize = (double) len;
        } else if ("K".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1024;
        } else if ("M".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1048576;
        } else if ("G".equals(unit.toUpperCase())) {
            fileSize = (double) len / 1073741824;
        }
        if (fileSize > size) {
            return false;
        }
        return true;
    }

    /**
     * 热度伪造：
     * 普通品牌，引流数低于2000的，乘以10倍显示
     * 厉害的品牌：引流数大于3000的，乘以0.6 （减少30%-40%）
     * 不被对方看出我们哪个品牌比较厉害
     *
     * @param var
     * @return
     */
    public static Integer setArticleHotValue(Integer var) {
        if (var == null || var <= 0) {
            return ToolUtil.randomNum(500, 5000);
        }

        if (var < 2000) {
            return var * 10;
        }

        if (var > 3000) {
            return var * 60 / 100;
        }

        return var;
    }

    /**
     * 获取当前时间的 年-月-日 格式
     * @return 当前时间的 年-月-日 格式
     */
    public static String getTodayYMD() {
        Date date = new Date(); // 此时date为当前的时间
        SimpleDateFormat dateFormat = new SimpleDateFormat("YYYY-MM-dd"); // 设置当前时间的格式，为年-月-日

        return dateFormat.format(date);
    }

    /**
     * 判断是不是今天
     * @param compareDate 年-月-日(2021-02-02)
     * @return true/false
     */
    public static boolean isToday(String compareDate) {

        return getTodayYMD().equals(compareDate);
    }

    /**
     * 获取 url 后面参数
     * @param url
     * @param name
     * @return
     */
    public static String getParam(String url, String name) {
        String params = url.substring(url.indexOf("?") + 1, url.length());
        Map<String, String> split = Splitter.on("&").withKeyValueSeparator("=").split(params);
        return split.get(name);
    }

    /**
     * 方法描述: 过滤分享链接的中文汉字
     *
     * @param url
     * @Return {@link String}
     */
    public static String filterUrl(String url) {
        String regex = "https?://(\\w|-)+(\\.(\\w|-)+)+(/(\\w+(\\?(\\w+=(\\w|%|-)*(\\&\\w+=(\\w|%|-)*)*)?)?)?)+";//匹配网址
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(url);
        if (m.find()) {
            return url.substring(m.start(), m.end());
        }
        return "";
    }

    /**
     * 过滤分享链接的中文汉字
     * @param data
     * @return
     */
    public static String findUrlByStr(String data) {
//		data = "地球亚洲中国https://www.baidu.com/s?wd=java 厉害厉害！";
        Pattern pattern = Pattern.compile("https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]");
        Matcher matcher = pattern.matcher(data);
        if (matcher.find()) {
            return matcher.group();
        }
        return "";
    }

}
